package com.mac.intellect_flow.admin.controller.system;

import com.mac.intellect_flow.reply.PageParam;
import com.mac.intellect_flow.reply.PageResult;
import com.mac.intellect_flow.reply.R;
import com.mac.intellect_flow.sys.entity.SysNotice;
import com.mac.intellect_flow.sys.service.SysNoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告 信息操作处理
 * 
 * @author mac
 */
@Tag(name = "通知公告")
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController {
    @Autowired
    private SysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @Operation(summary = "获取通知公告分页列表")
    @PreAuthorize("@ps.hasPermi('system:notice:list')")
    @GetMapping("/list")
    public R<PageResult<SysNotice>> list(SysNotice notice, PageParam pageParam) {
        return R.success(noticeService.queryPage(notice, pageParam));
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @Operation(summary = "根据通知公告编号获取详细信息")
    @PreAuthorize("@ps.hasPermi('system:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public R getInfo(@PathVariable Long noticeId) {
        return R.success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @Operation(summary = "新增通知公告")
    @PreAuthorize("@ps.hasPermi('system:notice:add')")
    @PostMapping
    public R add(@Validated @RequestBody SysNotice notice) {
        return R.success(noticeService.insertNotice(notice));
    }

    /**
     * 修改通知公告
     */
    @Operation(summary = "修改通知公告")
    @PreAuthorize("@ps.hasPermi('system:notice:edit')")
    @PutMapping
    public R edit(@Validated @RequestBody SysNotice notice) {
        return R.success(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    @Operation(summary = "删除通知公告")
    @PreAuthorize("@ps.hasPermi('system:notice:remove')")
    @DeleteMapping("/{noticeIds}")
    public R remove(@PathVariable Long[] noticeIds) {
        return R.success(noticeService.deleteNoticeByIds(noticeIds));
    }
}
